﻿Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors

Public Class Form2


    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'PcvgppDataSet.hanghoa' table. You can move, or remove it, as needed.
        Me.HanghoaTableAdapter.Fill(Me.PcvgppDataSet.hanghoa)
        Me.Hanghoa_donvitinhTableAdapter.Fill(Me.PcvgppDataSet.hanghoa_donvitinh)
        Me.DonvitinhTableAdapter.Fill(Me.PcvgppDataSet.donvitinh)
        Me.IGridView1.setReadonly(False)
    End Sub
    Private Sub batFocusGrid()
        '========== bắt focus trên lưới ===========
        IGridView1.FocusedRowHandle = Me.IGridView1.RowCount
        IGridView1.FocusedColumn = IGridView1.VisibleColumns(0)
        IGridView1.ShowEditor()
        '============================
    End Sub
    Private Sub MaTextEdit_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MaTextEdit.KeyDown
        If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) Then
            ' 'thêm dòng mới
            Me.IGridView1.Focus()
            batFocusGrid()
            Me.IGridView1.SetFocusedRowCellValue("ma", Me.MaTextEdit.EditValue)
            IGridView1.AddNewRow()
        End If
    End Sub

    Private Sub IGridView1_ShowingEditor(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles IGridView1.ShowingEditor
        Dim View As GridView = sender
        If TypeOf View.ActiveEditor Is SearchLookUpEdit Then
            'If TypeOf view.ActiveEditor Is SearchLookUpEdit Then
            DirectCast(View.ActiveEditor, SearchLookUpEdit).ShowPopup()
        End If
    End Sub

    Private Sub IGridView1_ShownEditor(sender As Object, e As System.EventArgs) Handles IGridView1.ShownEditor
        Dim View As GridView = sender
        If TypeOf View.ActiveEditor Is SearchLookUpEdit Then
            'If TypeOf view.ActiveEditor Is SearchLookUpEdit Then
            DirectCast(View.ActiveEditor, SearchLookUpEdit).ShowPopup()
        End If
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Try
            Me.FKhanghoadonvitinhhanghoaBindingSource.EndEdit()
            Me.Hanghoa_donvitinhTableAdapter.Update(Me.PcvgppDataSet.hanghoa_donvitinh)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        
    End Sub
End Class